package com.njust.diary.dao;

import com.njust.diary.po.Health;
import com.njust.diary.po.NoteType;
import lombok.experimental.Helper;

import java.util.ArrayList;
import java.util.List;

public class HealthDao {
    public static Integer checkUserId(Integer userId) {
        String sql ="select * from tb_health where userId =?";
        List<Object> params = new ArrayList<>();
        params.add(userId);
        Health health = (Health) BaseDao.queryRow(sql,params,Health.class);
        if(health==null){
            return 1;//此用户没这个类，可添加
        }else{
            return 0;
        }

    }


    public static int insert(Health health) {

        String sql="INSERT INTO tb_health (gender, age, height, userId, weight, xue1, xue2, xue3, xin1, xin2, xin3, yi1, yi2, yi3, jiao1, jiao2) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);";
        List<Object> params=new ArrayList<>();
        params.add(health.getGender());
        params.add(health.getAge());
        params.add(health.getHeight());
        params.add(health.getUserId());
        params.add(health.getWeight());
        params.add(health.getXue1());
        params.add(health.getXue2());
        params.add(health.getXue3());
        params.add(health.getXin1());
        params.add(health.getXin2());
        params.add(health.getXin3());
        params.add(health.getYi1());
        params.add(health.getYi2());
        params.add(health.getYi3());
        params.add(health.getJiao1());
        params.add(health.getJiao2());
        int row =BaseDao.executeUpdate(sql,params);
        return row;
    }

    public static int update(Health health) {
        String sql="update tb_health set gender = ?, age = ?, height = ?, weight = ?, xue1 = ?, xue2 = ?, xue3 = ?, xin1 = ?, xin2 = ?, xin3 = ?, yi1 = ?, yi2 = ?, yi3 = ?, jiao1 = ?, jiao2 = ? where userId = ?";
        List<Object> params=new ArrayList<>();
        params.add(health.getGender());
        params.add(health.getAge());
        params.add(health.getHeight());
        params.add(health.getWeight());

        params.add(health.getXue1());
        params.add(health.getXue2());
        params.add(health.getXue3());
        params.add(health.getXin1());
        params.add(health.getXin2());
        params.add(health.getXin3());
        params.add(health.getYi1());
        params.add(health.getYi2());
        params.add(health.getYi3());
        params.add(health.getJiao1());
        params.add(health.getJiao2());
        params.add(health.getUserId());
        int row =BaseDao.executeUpdate(sql,params);
       return row;
    }
//    String sql ="select noteId,title,content,pubTime,typeName,n.typeId from tb_note n inner join tb_note_type t on n.typeId=t.typeId where noteId = ?";
//    List<Object> params = new ArrayList<>();
//        params.add(noteId);
    public Health findHealthByUserId(Integer userId) {
        String sql ="select gender,age,height,weight,userId,xue1,xue2,xue3,xin1,xin2,xin3,yi1,yi2,yi3,jiao1,jiao2 from tb_health where userId = ?";
        List<Object> params=new ArrayList<>();
        params.add(userId);
        Health health =(Health) BaseDao.queryRow(sql,params,Health.class);
        return health;


    }
}
